<?php

class mypaging2{
	static public function paging2($totalPage, $currentPage, $minPage, $previousPage, $nextPage, $maxPage)
	{
	    $minPage = ($currentPage - 1 > 1 ? ($currentPage - 1) : 1);
	    $maxPage = ($currentPage + 1 < $totalPage ? ($currentPage + 1) : $totalPage);
	    $previousPage = $currentPage - 1;
	    $nextPage = $currentPage + 1;
	}
	
	
	static public function showPageAjax($totalPage, $page,$task, $userId,$from=NULL,$to=NULL)
	{
	    if ($totalPage > 1)
	    {
	        $minPage = 0;
	        $maxPage = 0;
	        $previousPage = 0;
	        $nextPage = 0;
	        #mypaging2::paging2($totalPage, $page, & $minPage, & $previousPage, & $nextPage, & $maxPage);
	        $minPage = ($page - 1 > 1 ? ($page - 1) : 1);
		    $maxPage = ($page + 1 < $totalPage ? ($page + 1) : $totalPage);
		    $previousPage = $page - 1;
		    $nextPage = $page + 1;
	    
	
	        if ($minPage == 1)
	        {
	            $linkToFirst = '';
	        }
	        else
	        if ($minPage == 2)
	        {
	        	#$linkToFirst = " <a href=\"javascript:showresult('$updateZone','$task','$userId','$type','$time','1')\">1</a>";
	        	$linkToFirst = " <a href=\"javascript:showfilter('$userId','$from','$to','$task','1')\">1</a>";
	        }
	        else
	        {
	            #$linkToFirst = " <a href=\"javascript:showresult('$updateZone','$task','$userId','$type','$time','1')\">1</a>...";
	            $linkToFirst = " <a href=\"javascript:showfilter('$userId','$from','$to','$task','1')\">1</a>...";
	        }
	
	        if ($maxPage == $totalPage)
	        {
	            $linkToLast = '';
	        }
	        else
	        if ($maxPage == $totalPage - 1)
	        {
	            #$linkToLast = " <a href=\"javascript:showresult('$updateZone','$task','$userId','$type','$time','$totalPage')\">$totalPage</a>";
	            $linkToLast = " <a href=\"javascript:showfilter('$userId','$from','$to','$task','$totalPage')\">$totalPage</a>";
	        }
	        else
	        {
	            #$linkToLast = " ...<a href=\"javascript:showresult('$updateZone','$task','$userId','$type','$time','$totalPage')\">$totalPage</a>";
	            $linkToLast = " ...<a href=\"javascript:showfilter('$userId','$from','$to','$task','$totalPage')\">$totalPage</a>";
	        }
	
	        $linkToPage = '';
	        for ($i = $minPage; $i <= $maxPage; $i++)
	        {
	            $linkToPage.= ($i == $page ? '<li><a class="page_current">'.$i.'</a></li>':"<a href=\"javascript:showfilter('$userId','$from','$to','$task','$i')\">$i</a>");
	        }
	        echo  '<div class="paging_comment row clearfix">'.
	        	'<div class="paging">Trang: 
	                     <ul>                                    
	                         <li>'.$linkToFirst.'</li>'.                         
	        					$linkToPage.
	                        '<li>'.$linkToLast.'</li>
	                     </ul>
	                   </div>
	               </div>';        
	    }
	}
	
	static public function showPageAjax2($totalPage, $page,$url, $userPhone)
	{
	    if ($totalPage > 1)
	    {
	        $minPage = 0;
	        $maxPage = 0;
	        $previousPage = 0;
	        $nextPage = 0;
	        $minPage = ($page - 1 > 1 ? ($page - 1) : 1);
		    $maxPage = ($page + 1 < $totalPage ? ($page + 1) : $totalPage);
		    $previousPage = $page - 1;
		    $nextPage = $page + 1;
	    
	
	        if ($minPage == 1)
	        {
	            $linkToFirst = '';
	        }
	        else
	        if ($minPage == 2)
	        {
	        	$linkToFirst = " <a href=\"javascript:showpage('$userPhone','1','$url')\">1</a>";
	        }
	        else
	        {
	            $linkToFirst = " <a href=\"javascript:showpage('$userPhone','1','$url')\">1</a>...";
	        }
	
	        if ($maxPage == $totalPage)
	        {
	            $linkToLast = '';
	        }
	        else
	        if ($maxPage == $totalPage - 1)
	        {
	            $linkToLast = " <a href=\"javascript:showpage('$userPhone','$totalPage','$url')\">$totalPage</a>";
	        }
	        else
	        {
	            $linkToLast = " ...<a href=\"javascript:showpage('$userPhone','$totalPage','$url')\">$totalPage</a>";
	        }
	
	        $linkToPage = '';
	        for ($i = $minPage; $i <= $maxPage; $i++)
	        {
	            $linkToPage.= ($i == $page ? '<li><a class="page_current">'.$i.'</a></li>':"<a href=\"javascript:showpage('$userPhone','$i','$url')\">$i</a>");
	        }
	        echo  '<div class="paging_comment row clearfix">'.
	        	'<div class="paging">Trang: 
	                     <ul>                                    
	                         <li>'.$linkToFirst.'</li>'.                         
	        					$linkToPage.
	                        '<li>'.$linkToLast.'</li>
	                     </ul>
	                   </div>
	               </div>';        
	    }
	}
}
?>